<template>
  <div>
    <form action="/">
      <van-search
        v-model="value"
        show-action
        placeholder="请输入搜索关键词"
        @search="onSearch"
        @cancel="onCancel"
      />
    </form>

    <div class="history">
        <div class="tit">历史记录</div>
        <p>
<a href="#" v-for="(item,index) in history" :key="index" ><i @click="onSearch(item)">{{item}}</i> <span @click="del(index)">x</span> </a>
        </p>
    </div>
    <div class="hotSear">
         <div class="tit">大家都在搜</div>
        <p>
            <a href="#"  v-for="(item,index) in mock" :key="index" @click="onSearch(item)">{{item}}</a>
            
        </p>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Search } from "vant";
Vue.use(Search);
import { Toast } from "vant";
export default {
  data() {
    return {
      value: "",
      history:[],
      mock:['水杯','人','电脑支架','牛','猪蹄','炸鸡']
    };
  },
  methods: {
    onSearch(val) {
      Toast(val);
      this.$store.dispatch('SETHISTORY',val)
      this.$router.push({name:'searResult',query:val})
    },
    onCancel() {
      Toast("取消");
      this.$router.go(-1)
    },
    del:function(id){
      console.log(id);
      this.$store.dispatch('DELSINGLE',id)
    },

  },
  created () {
    this.history=this.$store.getters.getHistory
    console.log(this.history);
  }
};
</script>

<style lang="scss" scoped>
.history p a{
  padding-right: 0 !important;
}
.history,.hotSear {
  height: 9rem;
  padding-left: 0.875rem;
  margin-bottom: 1.25rem;
  overflow: hidden;
  .tit {
    height: 2.8125rem;
    line-height: 2.8125rem;
    font-size: 1rem;
    color:#999999;
    text-align: left;
  }
  p {
    width: 22.5rem;
    display: flex;
    justify-content: left;
    flex-wrap: wrap;
    a {
      height: 2.25rem;
      padding: 0 0.625rem;
      line-height: 2.25rem;
      text-align: center;
      color: #848482;
      border: 1px solid #dfdfdf;
      margin-bottom: 0.875rem;
      margin-right: 0.75rem;
      span{
        color: black;
        width: 30px;
        height: 30px;
        display: inline-block;
        float: right;
      }
    }
  }
}
</style>